#!/usr/bin/env python3.12
# -*- coding: utf-8 -*-

import os
import time
import random
import json
import pathlib

aishuati_dir = pathlib.Path(__file__).parent.parent.parent.absolute() / "aishuati"
curpath = pathlib.Path(__file__).parent.absolute()

main_dir = "/home/mjp/git/bishuati/"
if __name__ == "__main__":
    # *********************生成public.js**********************
    JSONList = []
    directory = pathlib.Path(main_dir + "json")
    # json_files = [file.name for file in directory.iterdir() if file.is_file()]
    for file in directory.iterdir():
        if file.is_file():
            JSONList.append(
                {
                    "id": file.stem,
                    "name": file.stem,
                    "describe": file.stem,
                    "file": file.name,
                }
            )
    print(sorted(JSONList, key=lambda x: x["id"]))
    with open(aishuati_dir / "js/public.js", "w", encoding="utf-8") as f:
        f.write("var JSONList = ")
        json.dump(
            sorted(JSONList, key=lambda x: x["id"]), f, ensure_ascii=False, indent=4
        )

#   {
#     id: "判断题_101-150",
#     name: "判断题101-50",
#     describe: "",
#     file: "判断题_101-150.json",
#   }
